import numpy

class society_network:
    def __init__(self, N):
        self.N = N
        self.matrix = numpy.zeros((self.N, self.N))

    def begin_net(self):
        for i in range(0, self.N):
            for j in range(0, self.N):
                if not i == j:
                    self.matrix[i, j] = 1

        # self.matrix[1, 2] = 1
        # self.matrix[1, 3] = 1
        # self.matrix[2, 1] = 1
        # self.matrix[3, 1] = 1
        return self.matrix

    def update(self, isolated_people):

        '''
        用touch_record矩阵现在用来存储最近一次接触行为在x天前
        对该矩阵处理若本次无接触则该矩阵对应值 + 1，若有接触行为则置为1；
        '''
        self.touch_sum = numpy.zeros((self.N, self.N))
        for i in range(0, self.N):
            for j in range(0, self.N):
                if not i == j:
                    self.touch_sum[i, j] = 1

        self.isolated_people = isolated_people

        for i in range(self.N):
            for j in range(self.N):
                if self.touch_sum[i][j] == 0 and i != j:
                    if self.matrix[i][j] > 0:
                        self.matrix[i][j] += 1
                    else:
                        pass
                elif self.touch_sum[i][j] == 1:
                    # 如果当前个体是被隔离者，则当作本次无接触处理，即忽略接触行为
                    if (i in self.isolated_people) or (j in self.isolated_people):
                        self.matrix[i][j] += 1

                    else:
                        self.matrix[i][j] = 1

                if self.matrix[i][j] > 3:
                    self.matrix[i][j] = 0
